package com.network.chatsoft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.network.chatsoft.entity.MessageEntity;
import com.network.chatsoft.mapper.MessageMapper;
import com.network.chatsoft.service.MessageService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service(value = "message")
public class MessageServiceImpl extends ServiceImpl<MessageMapper, MessageEntity> implements MessageService {

    /**
     * 查询当前登录用户是否有文件，返回值是发送方，谁给当前用户发送的文件
     * @param username
     * @return
     */
    public List<String> getMessage(String username){
        LambdaQueryWrapper<MessageEntity> qw=new LambdaQueryWrapper<>();
        qw.eq(Strings.isNotEmpty(username),MessageEntity::getReceiverName,username);
        qw.eq(true,MessageEntity::getStatus,1);
        List<MessageEntity> list = this.list(qw);
        List<String> res=new ArrayList<>();
        for(int i=0;i<list.size();i++) res.add(list.get(i).getSenderName());
        return res;
    }

    /**
     * 文件上传完成后，通过此方法向消息数据库中插入数据，等待消费
     * @param username
     * @param receivername
     */
    public void sendMessage(String username,String[] receivername){

    }

    /**
     * 每次打开文件下载网页时运行，默认将所有文件都查看了，将status设为2，这样上面的getMessage就查不到了
     * @param username
     */
    public void consumeMessage(String username){

    }
}
